
// 发送ajax请求 获取页面信息
function pinlun(){
    $.ajax({
        type:'get',
        url:`/admin/comments`,
        success:function(res){
            if(res.status===0){
                let str = ''
                res.data.forEach(item => {
                    str += ` < <tr>
                    <td>${item.id}</td>
                    <td>${item.uname}</td>
                    <td>${item.content}</td>
                    <td>${item.cdate }</td>
                    <td>
                     <button data-id="${item.id}" type="button" class="layui-btn layui-btn-xs layui-btn-danger delete">
                        删除
                      </button>
                    </td>
                  </tr> `
                });
                $('tbody').html(str)
            }
         
            
        }
    })
}
pinlun()

$('tbody').on('click', '.delete', function () {

    let id = $(this).data('id');

    layer.confirm('确定删除？', { icon: 3, title: '提示' }, function (index) {
        //do something
        $.ajax({
            type: 'delete',
            url: '/admin/comments/' + id,
            success: function (res) {
              if (res.status === 0) {
                // 关闭窗口
                layer.close(index)
                layer.msg(res.message)
                // 刷新页面
                pinlun()
              }
            }
          })
        layer.close(index);

    })
})
